<?php
/**
 * Created by PhpStorm.
 * User: nightelf
 * Date: 2020/1/10
 * Time: 15:07
 */

namespace App\Http\Model;


use Illuminate\Support\Facades\DB;

class AssignmentLabelModel
{
    const TABLE = 'assignment_label';

    /**
     * @param array $where
     * @return array
     */
    public function info(array $where)
    {
        $result = DB::table(self::TABLE)->where($where)->first();
        return empty($result) ? [] : get_object_vars($result);
    }


    /**
     * @param array $check
     * @param $id
     * @return array
     */
    public function checkRepeat(array $check, $id = 0)
    {
        $result = DB::table(self::TABLE)->where($check)
            ->where(function ($query) use ($id){
                if ($id != 0){
                    $query->where('id','!=',$id);
                }
            })
            ->first();
        return empty($result) ? [] : get_object_vars($result);
    }

    /**
     * @param array $data
     * @return mixed
     */
    public function insert(array $data)
    {
        return DB::table(self::TABLE)->insertGetId($data);
    }

    /**
     * @return mixed
     */
    public function lists(){
        return DB::table(self::TABLE)->get()->toArray();
    }
}